package com.it.plic;

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.UUID;

/**
 * @author げっしょく
 * @date 2021/8/8
 */
public class Demo7_1 {

    public static void main(String[] args) throws IOException {
        ServerSocket s = new ServerSocket(10000);
        while (true) {
            UUID uuid = UUID.randomUUID();
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("Day16\\" + uuid.toString().replace("-", "") + ".txt"));
            //BufferedOutputStream  = new BufferedOutputStream(new FileOutputStream("Day16\\info.txt"));
            Socket accept = s.accept();
            InputStream is = accept.getInputStream();
            int a;
            while ((a = is.read()) != -1){
                bos.write(a);
            }
            accept.shutdownInput();

            BufferedOutputStream bs = new BufferedOutputStream(accept.getOutputStream());
            bs.write("收到了，over".getBytes());
            bs.close();
            bos.close();
            is.close();
        }
    }
}
